package com.doghome.mysb.web.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import com.doghome.mysb.service.LoginService;
import com.doghome.mysb.utils.AjaxResult;

@RestController
public class LoginController {
	
	private LoginService logingService;
	
	
	@Autowired
	public LoginController(LoginService logingService) {
		this.logingService = logingService;
	}


//	@CrossOrigin
	@PostMapping("/login")
	public AjaxResult login(@RequestBody Map<String, String> params) {
		Map<String, Object> map = logingService.login(params.get("userCode"), params.get("password"));
		return AjaxResult.success()
				.add("token", map.get("jwt").toString())
				.add("userName", map.get("userName").toString());
	}

}
